<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #app{
            border: 1px solid #cccccc;
            padding: 10px;
        }
        .box{
            border: 1px solid #cccccc;
            margin-left: 50px;
            padding: 10px;
        }
        p{
            padding-left: 20px;
        }
        input{
            margin-left: 20px;
        }
    </style>
    <script src="./js/vue.js"></script>
</head>
<body>
    <div id="app">
        <h3>父组件范围</h3>
        <child-one :msg="temp"></child-one>
        <br>
        <child-two @update-msg="updateMsg"></child-two>
    </div>
</body>
<script type="text/x-template" id="one">
    <div class="box">
        <h3>子组件-one-范围</h3>
        <p>msg:{{ msg }}</p>
    </div>
</script>
<script type="text/x-template" id="two">
    <div class="box">
        <h3>子组件-two-范围</h3>
        <p>msg:{{ msg }}</p>
        <input type="button" value="发送msg变量" @click="sendMsg()">
    </div>
</script>
<script>
    Vue.component("ChildOne",{
        template:"#one",
        props:["msg"]
    })
    Vue.component("ChildTwo",{
        template:"#two",
        data(){
            return {
                msg:"组件2的msg变量"
            }
        },
        methods: {
            sendMsg(){
                this.$emit("update-msg",this.msg)
            }
        },
    })
    new Vue({
        el:"#app",
        data:{
            temp:""
        },
        methods: {
            updateMsg(nv){
                this.temp = nv;
            }
        },
    })


</script>
</html>